package swu.cx.lock

import android.content.Context
import java.util.prefs.Preferences

class SharedPreference private constructor(){
    private val FILE_NAME="password"
    private val KEY="Key"
   companion object{
       private var mcontext: Context?=null
       private var instance:SharedPreference?=null
       fun getInstance(context: Context):SharedPreference{
           mcontext=context
           if (instance==null){
               synchronized(this){
                   if (instance==null){
                       instance= SharedPreference()
                   }
               }
           }
           return instance!!
       }
   }
    fun savePwd(pwd:String){
        mcontext?.getSharedPreferences(FILE_NAME,Context.MODE_PRIVATE).also {
            it?.edit()?.apply {
                putString(KEY,pwd)
                //提交
                apply()
            }
        }
    }
    fun getPwd():String?{
        mcontext?.getSharedPreferences(FILE_NAME,Context.MODE_PRIVATE).also {
            return it?.getString(KEY,null)
        }
    }
}